<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta content="width=750,viewport-fit=cover,user-scalable=no" name="viewport">
<meta content="yes" name="apple-mobile-web-capable">
<meta content="black" name="apple-mobile-web-status-bar-style">
<title>地址</title>
<link rel="stylesheet" type="text/css" href="../css/address.css" />
</head>
<body>
<div id="app" >
	<div class="menuBox menu" id="myTicket" v-for="address in addressList">
		<div class="menuBob">
			<img alt="" src="../image/myTicket.png">
		</div>
		<div class="menuBop">
			{{address.address}}-{{address.name}}-{{address.phone}}
		</div>
		<div class="right update" :data-id="address.id" @click="update($event)" style="color: #3e92ff">
			修改
		</div>
		<div class="right del" :data-id="address.id" @click="del($event)" style="color: #ff211a">
			删除
		</div>
		<div v-show="(!(goodsId==null)&&!(goodsId==''))" class="right yes" :data-id="address.id" @click="confirmDialog($event)" style="color: #ff211a">
			确定
		</div>
	</div>

	<div v-show="addressList.length == 0">
		<img src='../image/none.jpg' style='width: 300px;height:300px;margin-left: 225px;margin-top:100px;'>
	</div>

	<div>
		<div class="submit" @click="add($event)">新增地址</div>
		<!--<input type="submit" value="新增地址" class="submit" @click="add($event)" />-->
	</div>
</div>
</body>
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
<script type="text/javascript" src="../js/jquery-3.4.1.js"></script>
<script type="text/javascript" src="../js/user.js"></script>
<script type="text/javascript" src="../js/alert.js"></script>
<script type="text/javascript" src="../js/vue.js"></script>
<script type="text/javascript" src="../js/request.js"></script>
</html>

<script type="text/javascript">
	new Vue({
		el:'#app',
		data:{
			goodsId:'',
			goods:{},
			addressList:[],
		},
		methods:{
			//获取广告列表
			getAdList(){
				var _this = this;
				ajaxPost("../addressController/list",{}, function (result) {
					_this.addressList = result;
				});
			},
			del(event){
				var _this = this;
				var id = $(event.currentTarget).data("id");//地址ID
				ajaxPost("../addressController/del",{"id":id}, function (result) {
					_this.getAdList();
				});
			},
			update(event){
				var id = $(event.currentTarget).data("id");//地址ID
				window.location.href = "../html/updataaddress.html?id="+id+"&type=update&goodsId="+this.goodsId;//修改页面
			},
			add(event){
				var id = $(event.currentTarget).data("id");//地址ID
				window.location.href = "../html/updataaddress.html?id="+id+"&type=add&goodsId="+this.goodsId;//修改页面
			},
			getGoods() {
				var _this = this;//../NotifyReqController/NotifyReq
				ajaxGet("../goodsController/getById", {"id":_this.goodsId}, function (result) {
					_this.goods = result;
				});
			},
			getUrlKey(name) {
				return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || null
			},
			confirmDialog(event){
				if(confirm("确定兑换"+this.goods.name+"吗？选择确定将会成功兑换，否则请取消")){
					var _this = this;
					var addressId = $(event.currentTarget).data("id");//地址ID
					ajaxPost("../NotifyReqController/goodsPay",{"addressId":addressId,"goodsId":_this.goodsId}, function (result) {
						if(result.status){
							alert(result.data);
							window.location.href = "../html/orderList.html";//订单页面
						}else{
							alert(result.data);
						}
					});
				}else{
					alert("您已取消兑换操作");
				}
			},
		},
		created() {
			//获取地址栏参数 往商品ID
			this.goodsId = this.getUrlKey('goodsId')
		},
		mounted(){
			this.getAdList();
			if(this.goodsId != ''){
				this.getGoods();
			}
			console.log("挂载完成生命周期");
		},
	})
</script>
